package com.benew.ntt.evaluate.utils

import com.benew.ntt.evaluate.constant.EvalConst
import java.io.File

object EvalFileUtils {

    private const val KEEP_TIME = 5 * 24 * 60 * 60 * 1000L

    /**
     * 删除N天前文件
     */
    fun deleteFilesNDaysAgo() {
        Thread {
            val dir = File(EvalConst.getRecordFilePath())
            if (dir.exists()) {
                val files = dir.listFiles()
                if (files != null) {
                    val currTime = System.currentTimeMillis()
                    //相对于现在N天前时间
                    val beforeTIme = currTime - KEEP_TIME
                    for (file in files) {
                        if (file.lastModified() < beforeTIme) { //N天前的文件
                            file.delete()
                        }
                    }
                }
            }
        }.start()
    }
}